package com.xiaoyu.lanling.feature.invite.controller

import `in`.srain.cube.views.list.CubeRecyclerViewSimpleAdapter
import `in`.srain.cube.views.list.PagedListDataModelWithRequestTag
import android.content.Context
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.xiaoyu.base.event.AppEventBus
import com.xiaoyu.base.event.SimpleEventHandler
import com.xiaoyu.base.view.list.BaseListViewController
import com.xiaoyu.lanling.event.invite.list.InviteListEvent
import com.xiaoyu.lanling.feature.invite.model.InviteItem
import com.xiaoyu.lanling.feature.invite.viewholder.InviteViewHolder
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

class InviteListController(val context: Context,
                           val listData: PagedListDataModelWithRequestTag<InviteItem, Any>,
                           val adapter: CubeRecyclerViewSimpleAdapter<InviteItem>,
                           val swipeRefreshLayout: SwipeRefreshLayout,
                           val recyclerView: RecyclerView)
    : BaseListViewController<InviteItem, Any>(context, listData, adapter, swipeRefreshLayout, recyclerView) {

    companion object {
        fun create(context: Context, listData: PagedListDataModelWithRequestTag<InviteItem, Any>, swipeRefreshLayout: SwipeRefreshLayout, recyclerView: RecyclerView): InviteListController {
            val adapter = CubeRecyclerViewSimpleAdapter<InviteItem>()
            adapter.setViewHolderClass(0, null, InviteViewHolder::class.java, 20)

            val controller = InviteListController(context, listData, adapter, swipeRefreshLayout, recyclerView)

            AppEventBus.bindContainerAndHandler(context, object : SimpleEventHandler() {
                @Subscribe(threadMode = ThreadMode.MAIN)
                fun onEvent(event: InviteListEvent) {
                    controller.onListEvent(event)
                }
            })
            return controller
        }
    }
}